package com.disability_federation.controller;

import com.disability_federation.mapper.MapperUnpaidEnterpriseList;
import com.disability_federation.pojo.UnpaidEnterpriseList;
import com.disability_federation.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 未缴费企业列表操作接口
 */
@RestController
@CrossOrigin
public class ControllerUnpaidEnterpriseList {

    @Autowired
    private MapperUnpaidEnterpriseList mapperUnpaidEnterpriseList;

    /**
     * 查询所有未缴费企业
     * 默认时间升序排序
     */
    @RequestMapping("UEL/query")
    public Result query() {
        return Result.success(mapperUnpaidEnterpriseList.query());
    }

    /**
     * 查询所有未缴费企业
     * 时间降序排序
     */
    @RequestMapping("UEL/query/time_desc")
    public Result queryDesc() {
        return Result.success(mapperUnpaidEnterpriseList.queryDesc());
    }

    /**
     * 查询所有未缴费企业
     * 企业名升序排序
     */
    @RequestMapping("UEL/query/enterprise_asc")
    public Result queryEnterpriseAsc() {
        return Result.success(mapperUnpaidEnterpriseList.queryEnterpriseAsc());
    }

    /**
     * 查询所有未缴费企业
     * 企业名降序排序
     */
    @RequestMapping("UEL/query/enterprise_desc")
    public Result queryEnterpriseDesc() {
        return Result.success(mapperUnpaidEnterpriseList.queryEnterpriseDesc());
    }

    /**
     * 查询所有未缴费企业
     * 金额升序排序
     */
    @RequestMapping("UEL/query/money_asc")
    public Result queryMoneyAsc() {
        return Result.success(mapperUnpaidEnterpriseList.queryMoneyAsc());
    }

    /**
     * 查询所有未缴费企业
     * 金额降序排序
     */
    @RequestMapping("UEL/query/money_desc")
    public Result queryMoneyDesc() {
        return Result.success(mapperUnpaidEnterpriseList.queryMoneyDesc());
    }

    /**
     * 条件查询未缴费企业
     * 默认时间升序排序
     */
    @RequestMapping("UEL/query/condition")
    public Result queryCondition(String enterprise, Integer sum1, Integer sum2) {
        return Result.success(mapperUnpaidEnterpriseList.queryCondition(enterprise, sum1, sum2));
    }

    /**
     * 条件查询未缴费企业
     * 时间降序排序
     */
    @RequestMapping("UEL/query/condition/time_desc")
    public Result queryConditionDesc(String enterprise, Integer sum1, Integer sum2) {
        return Result.success(mapperUnpaidEnterpriseList.queryConditionDesc(enterprise, sum1, sum2));
    }

    /**
     * 条件查询未缴费企业
     * 企业名升序排序
     */
    @RequestMapping("UEL/query/condition/enterprise_asc")
    public Result queryConditionEnterpriseAsc(String enterprise, Integer sum1, Integer sum2) {
        return Result.success(mapperUnpaidEnterpriseList.queryConditionEnterpriseAsc(enterprise, sum1, sum2));
    }

    /**
     * 条件查询未缴费企业
     * 企业名降序排序
     */
    @RequestMapping("UEL/query/condition/enterprise_desc")
    public Result queryConditionEnterpriseDesc(String enterprise, Integer sum1, Integer sum2) {
        return Result.success(mapperUnpaidEnterpriseList.queryConditionEnterpriseDesc(enterprise, sum1, sum2));
    }

    /**
     * 条件查询未缴费企业
     * 金额升序排序
     */
    @RequestMapping("UEL/query/condition/money_asc")
    public Result queryConditionMoneyAsc(String enterprise, Integer sum1, Integer sum2) {
        return Result.success(mapperUnpaidEnterpriseList.queryConditionMoneyAsc(enterprise, sum1, sum2));
    }

    /**
     * 条件查询未缴费企业
     * 金额降序排序
     */
    @RequestMapping("UEL/query/condition/money_desc")
    public Result queryConditionMoneyDesc(String enterprise, Integer sum1, Integer sum2) {
        return Result.success(mapperUnpaidEnterpriseList.queryConditionMoneyDesc(enterprise, sum1, sum2));
    }

    /**
     * 删除某条未缴费企业记录
     */
    @RequestMapping("UEL/delete")
    public Result delete(Integer id) {
        if(mapperUnpaidEnterpriseList.delete(id)>0){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

    /**
     * 新增一条未缴费企业记录
     */
    @RequestMapping("UEL/add")
    public Result add(String enterprise, String address, String phone, float sum, LocalDateTime payTime) {
        UnpaidEnterpriseList unpaidEnterpriseList = new UnpaidEnterpriseList();
        unpaidEnterpriseList.setEnterprise(enterprise);
        unpaidEnterpriseList.setAddress(address);
        unpaidEnterpriseList.setPhone(phone);
        unpaidEnterpriseList.setSum(sum);
        unpaidEnterpriseList.setPayTime(payTime);
        if(mapperUnpaidEnterpriseList.add(unpaidEnterpriseList)>0){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

    /**
     * 更新一条未缴费企业记录
     */
    @RequestMapping("UEL/update")
    public Result update(UnpaidEnterpriseList unpaidEnterpriseList) {
        if(mapperUnpaidEnterpriseList.update(unpaidEnterpriseList)>0){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

    /**
     * 批量删除未缴费企业记录
     */
    @RequestMapping("UEL/delete/batch")
    public Result deleteBatch(Integer[] ids) {
        if(mapperUnpaidEnterpriseList.deleteBatch(ids)>0){
            return Result.success(null);
        }
        else{
            return Result.fail();
        }
    }

}
